import { Component, OnInit } from '@angular/core';
import { MemberService } from '../member.server';
import { Router } from '@angular/router';
import { LayoutRourteStatus } from 'src/app/model/status';
import { MessageService } from 'src/app/core/service';
import { FormGroup, FormBuilder } from '@angular/forms';
import { TradeType, TradeTypes, formatDateGlob } from '../pipe-member/pipe.member';

@Component({
    templateUrl: './member-center-withdrawal.component.html',
    styleUrls: ['./member-center-withdrawal.component.scss']
})
export class MemberCenterWithdrawalComponent implements OnInit {
    private _layoutRourteStatus: LayoutRourteStatus = {
        url: '/member/center/getCoins',
        breadcrumbs: [{ tragetTitle: '提币申请列表' }]
    };
    validateForm: FormGroup;
    tradeTypes: TradeType[] = TradeTypes;
    private _msgList: Array<any>;
    private visible:boolean = false;;
    private _data: Array<any> = [];
    private _totalMap: any;
    private _config: Array<any> = [
        { 
            name: '操作',
            class: 'table-w-10-huanHang',
            key: 'cz',
            labels: [
                {
                    name: '查看',
                    type: 'click'
                },{
                    name: '上传',
                    type: 'click'
                }
            ]},
        {
            name: '申请时间',
            class: 'table-w-10-huanHang',
            key: 'regDtm'
        },
        {
            name: '提币金额',
            class: 'table-w-10-huanHang',
            key: 'amount'
        },
        {
            name: '手续费',
            class: 'table-w-10-huanHang',
            key: 'withdrawalFee'
        },
        {
            name: '提币地址',
            class: 'table-w-10-huanHang',
            key: 'toAddress'
        },
        {
            name: '状态',
            class: 'table-w-10-huanHang',
            key: 'status',
        }
    ];
    private _page: any = {
        pageNo: 1,
        pages: 1,
        totalCount: 10
    };
    ngOnInit() {
        this.msg.sendLayoutRourteStatus(this._layoutRourteStatus);
        this.resetForm();
        this.loadList('商户平台转帐列表');
    }
    resetForm(): void {
        this.validateForm = this.fb.group({
            status: ['All'],
            duration: [[]],
            outTradeNo: [null]
        });
        this._page = {
            pageNo: 1,
            pages: 1,
            totalCount: 10
        };
    }
    public onDtl(e): void {
        this.visible = true;
    }
    public close(): void {
        this.visible = false;
      }
    public onListClick(e): void {
        e.name === '查看' ? this.onDtl(e) : this.loadList('商户平台转帐列表');
    }
    public onSearch(type: string): void {
        this._page.pageNo = 1;
        if (type === 'reset') {this.resetForm(); }
        this.loadList('商户平台转帐列表');
    }
    async loadList(url) {
        const form = this.validateForm.value;
        const getSechData = {
            status: form.status,
            endDate: formatDateGlob(form.duration[1]),
            startDate: formatDateGlob(form.duration[0]),
            outTradeNo: form.outTradeNo
        };
        const data = Object.assign(this._page, getSechData);

        const tag = await this.memberServer.getAJX(url, data);
        if (this.memberServer.getApiSuccess(tag, false)) { this.successListOk(tag.data, url); }
    }
    public successListOk(data, url): void {
        switch (url) {
            case '商户平台转帐列表':
                this._page.pageNo = data.pageNo;
                this._page.pages = data.pages;
                this._page.totalCount = data.totalCount;
                console.log(data.list);
                this._data = data.list;
                this._totalMap = data;
                break;
        }
    }
    constructor(private memberServer: MemberService, private router: Router, private msg: MessageService, private fb: FormBuilder) {}
}
